#x,n,bitNum输入变量

GroupData<-function(x,n){
  ##数组长度
  m<-length(x)
  if((n-m%%n)%%n < ceiling(m/n)){
    x<-c(x,rep(NA,(n-m%%n)%%n))
  }else{
    for(i in (m%%n+1):n){
      if(i == n){
        x<-c(x[1:(ceiling(m/n)*i-1)],NA)
      }else{
        x<-c(x[1:(ceiling(m/n)*i-1)],NA,x[(ceiling(m/n)*i):length(x)])
      }
    }
  }
  group<-matrix(x,nrow=n,byrow=T)
  return(group)
  }

if(is.null(n) || n == 0) {
    n <- ceiling(sqrt(length(x)))
}

m <- length(x)
cl <- c(-3, -2, -1, 0, 1, 2, 3)
#group <- matrix(c(x, rep(NA, (n - m %% n) %% n)), ncol=n, byrow=T)
#group <- matrix(c(x, rep(NA, (n - m %% n) %% n)), nrow=n, byrow=T)
group <- GroupData(x,n)

#标准差
claData <- apply(group, 1, sd, na.rm=T)

#对比线
CL <- mean(claData, na.rm=T) + cl * sd(claData, na.rm=T)

#精确位数
#if (bitNum > 0) {
#    claData <- round(claData, bitNum)
#    CL <- round(CL, bitNum)
#}